package com.yyaccp.easybuy.security.controller;

import com.yyaccp.easybuy.other.R;
import com.yyaccp.easybuy.security.service.LoginService;
import com.yyaccp.easybuy.security.vo.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class LoginController {
    @Autowired
    private LoginService loginService;
    /**
     * 普通登录
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginUser loginUser) {
        return R.ok("登录成功", loginService.login(loginUser));
    }
    /**
     * 手机号码+验证码登录
     */
    @PostMapping("/sms/login")
    public R smsLogin(String phoneNumber, String validCode) {
        return R.ok("登录成功", loginService.smsLogin(phoneNumber, validCode));
    }
    /**
     * 发送短信验证码
     */
    @GetMapping("/sms/send/{phoneNumber}")
    public R sendValidCode(@PathVariable String phoneNumber) {
        loginService.sendValidCode(phoneNumber);
        return R.ok();
    }
}
